package jpa.service.synchro.staging;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import org.apache.log4j.Logger;
import promis.utility.CommonService;
import jpa.entitys.synchro.common.CommonEntity;
import jpa.entitys.synchro.staging.SyncQueue;
import jpa.entitys.synchro.staging.SyncQueueParam;
import jpa.service.synchro.common.JPAService;

public class SyncQueueParamServices extends JPAService {
	
	private static final Logger log = Logger.getLogger(SyncQueueParamServices.class);

	public SyncQueueParamServices(EntityManager em) {
		super(em);
	}
	
	public SyncQueueParam findById(String id) throws Exception {				
		return super.ConvertToYoureObject(super.find(id, "SyncQueueParam.findById"));				
	}
	
	public List<SyncQueueParam> findByQueueId(BigDecimal queueId) throws Exception {				
		Map<String,Object> mapWhereValue = new HashMap<String, Object>();
		mapWhereValue.put("queueId", queueId);
		
		return super.ConvertToYoureObject(super.find("SyncQueueParam.findByQueueId", mapWhereValue));
	}
	
	public SyncQueueParam Inserted(SyncQueueParam queue) throws Exception {
		try{
			List<CommonEntity> common_lst = new ArrayList<CommonEntity>();			
			if(CommonService.ConvertStringToLong(queue.getSyncQueueParamId()) <= 0)
			{
				String id = super.SequenceNext("SYNC_QUEUE_PARAM");					
				queue.setSyncQueueParamId(CommonService.ConvertStringToBigDecimal(id));
				queue.setProcCreatedby("PROC-QUEUE");
				queue.setProcCreatedon(this.getCurrent_date());
				
				common_lst.add(queue);
			}
			super.inserted(common_lst);
			
		}catch(Exception e)
		{
			log.error(e.getMessage());
			System.out.println(e.getMessage());
			throw e;
		}
		return queue;
	}
	
	public List<SyncQueueParam> Inserted(List<SyncQueueParam> vlauelist) throws Exception {
		try{
			List<CommonEntity> common_lst = new ArrayList<CommonEntity>();			
			for(SyncQueueParam obj : vlauelist)
			{
				if(CommonService.ConvertStringToLong(obj.getSyncQueueParamId()) <= 0)
				{
					String id = super.SequenceNext("SYNC_QUEUE_PARAM");
					obj.setSyncQueueParamId(CommonService.ConvertStringToBigDecimal(id));
					obj.setProcCreatedby("PROC-QUEUE");
					obj.setProcCreatedon(this.getCurrent_date());
					common_lst.add(obj);
				}
			}
			super.inserted(common_lst);
			
		}catch(Exception e)
		{
			log.error(e.getMessage());
			System.out.println(e.getMessage());
			throw e;
		}
		return vlauelist;
	}
	
	public List<SyncQueueParam> Updated(List<SyncQueueParam> vlauelist) throws Exception {
		try{
			List<CommonEntity> common_lst = new ArrayList<CommonEntity>();			
			for(SyncQueueParam obj : vlauelist)
				common_lst.add(obj);
			
			super.updated(common_lst);
			
		}catch(Exception e)
		{
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
		return vlauelist;
	}
	
}
